package com.example.metodo_post;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;

public class lista_articulos extends Activity  {
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.detalle_productos);
		
		String server_url = getIntent().getStringExtra("server_url");
        String cat_id = getIntent().getStringExtra("cat_id");
        
        ImageView img = (ImageView) findViewById(R.id.tipo_img);
        if(cat_id.equals("1") == true){
        	img.setImageResource(R.drawable.phone);
        }
        if(cat_id.equals("2") == true){
        	img.setImageResource(R.drawable.pc);
        }
        if(cat_id.equals("3") == true){
        	img.setImageResource(R.drawable.mis);
        }
        
        
        web_page url = new web_page();
		List<String> spinnerArray = new ArrayList<String>();
		spinnerArray = url.detalles_productos(server_url, cat_id);
        
        final Spinner spinner = (Spinner) findViewById(R.id.spinner_articulos);
        
        ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
		spinner.setAdapter(spinnerArrayAdapter);
        
		Button buscar_google = (Button) findViewById(R.id.btn_google);
		buscar_google.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Uri uri = Uri.parse("http://www.google.com/#q="+ spinner.getSelectedItem().toString() );
				Intent intent = new Intent(Intent.ACTION_VIEW, uri);
				startActivity(intent);
			}
		});
		
	}
}
